<?php

namespace app\apishop\validate;

use think\Validate;
use think\Db;

class Rules extends Validate{
    
    protected $rule = [
        'name' => 'require',
        'pwd' => 'require',
        'manager' => 'require',
        'tel' => 'require',
        'post_code' => 'require',
        'address' => 'require',
        'company_code' => 'require',
        'account' => 'require',
        'agreement' => 'require',
        'code' => 'require',
        'company'=>'require',
    ];
    
    protected $message = [
        'name.require' => '请输入用户名',
        'password.require' => '请输入密码',
        'manager.require' => '请输入负责人',
        'tel.require' => '请输入联系电话',
        'post_code.require' => '请输入邮政编码',
        'address.require' => '请输入所在地址',
        'company_code.require' => '请输入公司注册号码',
        'account.require' => '请输入账号',
        'agreement.require' => '请输入同意字段',
        'code.require' => '请输入验证码',
        'company.require' => '请输入正确的公司名称',
    ];
    
    protected $scene = [
        'login' => ['tel','password'],
        'register' => ['account','password','agreement'],
        'shopUpdate' => ['company','manager','tel','post_code','address','company_code'],
        'setSupplierInfo' => ['company','manager','tel','post_code','address','company_code'],
    ];
    /**
     * 检查手机号码合法性
     * @param type $value
     * @return boolean|string
     */
    protected function checkPhone($value){
        if(preg_match("/^1[34578]{1}\d{9}$/",$value)){  
            return TRUE;  
        }else{  
            return '手机号码有误';  
        }  
    }
    protected function aaa(){
        echo 5555;
    }
    /**
     * 检查邮箱地址合法性
     * @param type $value
     * @return boolean|string
     */
    protected function checkEmail($value){
        if(preg_match("/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i",$value)){  
            return TRUE;  
        }else{  
            return '邮箱地址有误';  
        } 
    }
    /**
     * 检查密码重复
     * @param type $value
     * @return boolean|string
     */
    protected function checkPassword(){
        $data = input('post.');
        if($data['user_password'] != $data['repassword']){
            return '两次密码输入不一致';
        }
        return TRUE;
    }
    
    /**
     * 检查房间类型是否存在
     * @param type $value
     * @return type
     */
}

